package com.northpool.operator.http;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.log.StaticLog;
import com.northpool.operator.http.runtime.HttpOperatorApp;
import com.northpool.operator.http.runtime.HttpOperatorAppV2;

public class Application {

    public static void main(String[] args) {
        try {
            if (ArrayUtil.isEmpty(args)) {
               StaticLog.error("参数错误");
                System.exit(1);
            }
            // 如果是类路径，则按进程级算子运行
            if (args[0].startsWith("com.northpool") && !args[0].endsWith(".xml")) {
                com.northpool.operator.common.algorithm.Application.main(args);
                return;
            }

            IHttpAlgorithm algorithm;
            if (args.length == 1) {
                // 如果是.xml结尾的
                algorithm = new HttpOperatorAppV2();
            } else if(args.length == 2) {
                algorithm = new HttpOperatorApp();
            } else {
                throw new RuntimeException("算子参数执行参数错误");
            }
            algorithm.execute(args);
            System.exit(0);
        } catch (Exception e) {
            StaticLog.error(e.getMessage(), e);
            e.printStackTrace();
            System.exit(1);
        }
    }
}
